Row

confirmed

952,803

active

78,593 (8.2%)

death

23,538 (2.5%)

recovered

850,672 (89.3%)

Column

Evolutie cazuri noi

Distributia cazurilor totale

Evolutia cazurilor cumulativ

Cazuri confirmate zilnic - tari vecine sau cu risc

Distributia cazurilor dupa tipul lor

Date

Click pe numele coloanei pentru a rearanja datele in tabel. Ultimul update al datelor a fost: 2021-03-31

Despre

Acest dashboard este o replica inspirata de articolul lui Antoine Soetewey.

Ulterior, dashboardurile dezvoltate de Rami Krispin, cat si pachetele de date COVID-19 au reprezentat un punct de explorare al pachetului R ‘{flexdashboard}’.

Code Codul este scris folosind R.

Data Momentan folosesc datele disponibile in pachetul de dezvoltare, dar initial s-au folosit date de intrare din pachetul R {coronavirus}.

install.packages("devtools")
devtools::install_github("RamiKrispin/coronavirus")

Datele brute au sursa datele de la Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus. Acestea sunt actualizate zilnic, dar acest dashboard se actualizeaza la cateva zile, manual.

Ultimul update Dashboardul a fost actualizat ultima oara in data de Apr 01, 2021. Datele raportate sunt pana la data de Mar 31, 2021

Pentru alte proiecte de R, ma gasesti pe pagina mea personala.

---
title: Romania covid-19 Dashboard

output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    source_code: embed
    vertical_layout: fill
    theme: bootstrap
---

```{r setup, include=FALSE}
#------------------ Packages ------------------
library(flexdashboard)
#install.packages("devtools")
#devtools::install_github("RamiKrispin/coronavirus", force = TRUE)

`%>%` <- magrittr::`%>%`

#------------------ Parameters ------------------
# Set colors
# https://www.w3.org/TR/css-color-3/#svg-color
confirmed_color <- "purple"
active_color <- "#1f77b4"
recovered_color <- "forestgreen"
death_color <- "red"

#------------------ Data ------------------
#data(coronavirus)
coronavirus <- read.csv("https://raw.githubusercontent.com/RamiKrispin/coronavirus/master/csv/coronavirus.csv", stringsAsFactors = FALSE)
coronavirus$date <- as.Date(coronavirus$date)

coronavirus <- coronavirus %>%
dplyr::filter(country == "Romania" |
    country == "Greece" |
    country == "Hungary" |
    country == "Sweden")

#------------------ Data Preparation ------------------
df <- coronavirus %>%
  dplyr::filter(country == "Romania") %>%
  dplyr::group_by(country, type) %>%
  dplyr::summarise(total = sum(cases)) %>%
  tidyr::pivot_wider(
          names_from = type,
          values_from = total) %>%
  dplyr::mutate(unrecovered = confirmed - ifelse(is.na(death), 0,death)-ifelse(is.na(recovered), 0, recovered)) %>%
  dplyr::arrange(-confirmed) %>%
  dplyr::ungroup()

df_daily <- coronavirus %>%
  dplyr::filter(country == "Romania") %>%
  dplyr::group_by(date, type) %>%
  dplyr::summarise(total = sum(cases, na.rm = TRUE)) %>%
  tidyr::pivot_wider(
    names_from = type,
    values_from = total
  ) %>%
  dplyr::arrange(date) %>%
  dplyr::ungroup() %>%
  dplyr::mutate(active = confirmed - death) %>%
  dplyr::mutate(
          confirmed_cum = cumsum(confirmed),
          death_cum = cumsum(death),
          recovered_cum = cumsum(recovered),
          active_cum = cumsum(active),
          daily_confirmed_5D = round((confirmed +
                                    dplyr::lag(confirmed, n = 1) +
                                    dplyr::lag(confirmed, n = 2) +
                                    dplyr::lag(confirmed, n = 3) +
                                    dplyr::lag(confirmed, n = 4))/5,digits = 0),
          daily_confirmed_7D = round((confirmed +
                                    dplyr::lag(confirmed, n = 1) +
                                    dplyr::lag(confirmed, n = 2) +
                                    dplyr::lag(confirmed, n = 3) +
                                    dplyr::lag(confirmed, n = 4) +
                                    dplyr::lag(confirmed, n = 5) +
                                    dplyr::lag(confirmed, n = 6))/7,digits = 0),
          daily_confirmed_14D = round((confirmed +
                                    dplyr::lag(confirmed, n = 1) +
                                    dplyr::lag(confirmed, n = 2) +
                                    dplyr::lag(confirmed, n = 3) +
                                    dplyr::lag(confirmed, n = 4) +
                                    dplyr::lag(confirmed, n = 5) +
                                    dplyr::lag(confirmed, n = 6) +
                                    dplyr::lag(confirmed, n = 7) +
                                    dplyr::lag(confirmed, n = 8) +
                                    dplyr::lag(confirmed, n = 9) +
                                    dplyr::lag(confirmed, n = 10) +
                                    dplyr::lag(confirmed, n = 11) +
                                    dplyr::lag(confirmed, n = 12) +
                                    dplyr::lag(confirmed, n = 13))/14,digits = 0)
          ) %>% 
    dplyr::mutate(
      recover_rate = round((recovered /confirmed), digits = 4),
      death_rate = round((death / confirmed),digits = 4)
      )
df_daily <-df_daily %>% dplyr::arrange(desc(date))

dft <- df_daily %>%
    dplyr::select(c("date", "confirmed", "recovered", "death","daily_confirmed_5D","daily_confirmed_7D","daily_confirmed_14D","recover_rate", "death_rate")) %>% 
  dplyr::filter(confirmed>0 | recovered>0 | death>0)

df1 <- coronavirus %>% dplyr::filter(date == max(date))


```


Row
-----------------------------------------------------------------------


### confirmed {.value-box}

```{r}
valueBox(
  value = paste(format(sum(df$confirmed), big.mark = ","), "", sep = " "),
  caption = "Total cazuri confirmate",
  icon = "fas fa-user-md",
  color = confirmed_color
)
```

### active {.value-box} 

```{r} 
valueBox(
value = paste(format(sum(df$unrecovered, na.rm = TRUE), big.mark = ","), " (",
round(100 * sum(df$unrecovered, na.rm = TRUE) / sum(df$confirmed), 1), 
"%)",
sep = "" 
), 
caption = "Cazuri active (% of total cazuri)", icon = "fas fa-bed", 
 color = active_color 
 ) 
```

### death {.value-box}

```{r}
valueBox(
  value = paste(format(sum(df$death, na.rm = TRUE), big.mark = ","), " (",
    round(100 * sum(df$death, na.rm = TRUE) / sum(df$confirmed), 1),
    "%)",
    sep = ""
  ),
  caption = "Cazuri deces (rata deces)",
  icon = "fas fa-frown",
  color = death_color
)
```

### recovered {.value-box}

```{r}
valueBox(
  value = paste(format(sum(df$recovered, na.rm = TRUE), big.mark = ","), " (",
    round(100 * sum(df$recovered, na.rm = TRUE) / sum(df$confirmed), 1),
    "%)",
    sep = ""
  ),
  caption = "Cazuri vindecati (rata de vindecare)",
  icon = "fas fa-user-check",
  color = recovered_color
)
```

Column {.tabset} 
-----------------------------------------------------------------------

### Evolutie cazuri noi

```{r}
plotly::plot_ly(data = df_daily,
                x = ~ date,
                y= ~ confirmed,
                type = "scatter",
                mode = "markers",
                name = "Confirmati") %>%
  plotly::add_lines(x = ~ date, 
                    y = ~ daily_confirmed_14D,
                    line = list(color = "grey", width = 1),
                    name = "trend 14 zile") %>%
    plotly::add_lines(x = ~ date, 
                    y = ~ daily_confirmed_7D,
                    line = list(color = "maroon", width = 1),
                    name = "trend 7 zile") %>%
      plotly::add_lines(x = ~ date, 
                    y = ~ daily_confirmed_5D,
                    line = list(color = "red", width = 2),
                    name = "trend 5 zile") %>%
  plotly::layout(title = "",
                 legend = list(x = 0.6, y = 0.9),
                 yaxis = list(title = "Number of Cases"),
                 xaxis = list(title = "Utilizarea mediei mobile pe 5, 7 and 14 zile pentru a evalua trendul"),
                 hovermode = "compare")
```

### Distributia cazurilor totale

```{r}
plotly::plot_ly(data = df_daily,
        x = ~ date,
        y = ~ confirmed_cum, 
        name = 'Activi', 
        fillcolor = 'blue',
        type = 'scatter',
        mode = 'none', 
        stackgroup = 'one') %>%
  plotly::add_trace( y = ~ death_cum,
             name = "Decedati",
             fillcolor = '#E41317') %>%
  plotly::add_trace(y = ~recovered_cum,
            name = 'Vindecati',
            fillcolor = 'forestgreen') %>%
  plotly::layout(title = "",
         legend = list(x = 0.1, y = 0.9),
         yaxis = list(title = "Cazuri confirmate"),
         xaxis = list(title = "Sursa: COVID package, JHU CCSE"),
         hovermode = "compared")
```

### Evolutia cazurilor cumulativ

```{r}
plotly::plot_ly(data = df_daily) %>%
  plotly::add_trace(
    x = ~date,
    y = ~confirmed_cum,
    type = "scatter",
    mode = "lines+markers",
    name = "Confirmati",
    line = list(color = active_color),
    marker = list(color = active_color)
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~death_cum,
    type = "scatter",
    mode = "lines+markers",
    name = "Decedati",
    line = list(color = death_color),
    marker = list(color = death_color)
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-02-04"),
    y = 1,
    text = paste("Primul caz"),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -10,
    ay = -90
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-03-22"),
    y = 22,
    text = paste("Primul deces"),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -10,
    ay = -90
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-03-14"),
    y = 22,
    text = paste(
      "Lockdown - Stare Urgenta"
    ),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -10,
    ay = -120
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-05-15"),
    y = 20,
    text = paste(
      "Stare de alerta"
    ),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -20,
    ay = -120
  ) %>%
    plotly::add_annotations(
    x = as.Date("2020-08-02"),
    y = 120,
    text = paste(
      "Masuri Noi"
    ),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -20,
    ay = -150
  ) %>%
    plotly::add_annotations(
    x = as.Date("2020-09-14"),
    y = 140,
    text = paste(
      "Deschiderea scolilor"
    ),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -10,
    ay = -200
  ) %>%
  plotly::layout(
    title = "",
    yaxis = list(title = "Numar de cazuri cumulativ"),
    xaxis = list(title = "Date"),
    legend = list(x = 0.1, y = 0.9),
    hovermode = "compare"
  )
```



### Cazuri confirmate zilnic - tari vecine sau cu risc
    
```{r}
daily_confirmed <- coronavirus %>%
  dplyr::filter(type == "confirmed") %>%
  dplyr::filter(date >= "2020-02-29") %>%
  dplyr::mutate(country = country) %>%
  dplyr::group_by(date, country) %>%
  dplyr::summarise(total = sum(cases)) %>%
  dplyr::ungroup() %>%
  tidyr::pivot_wider(names_from = country, values_from = total)
#----------------------------------------
# Plotting the data
daily_confirmed %>%
  plotly::plot_ly() %>%
  plotly::add_trace(
    x = ~date,
    y = ~Romania,
    type = "scatter",
    mode = "lines+markers",
    name = "Romania"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Hungary,
    type = "scatter",
    mode = "lines+markers",
    name = "Ungaria"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Greece,
    type = "scatter",
    mode = "lines+markers",
    name = "Grecia"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Sweden,
    type = "scatter",
    mode = "lines+markers",
    name = "Suedia"
  ) %>%
  plotly::layout(
    title = "",
    legend = list(x = 0.1, y = 0.9),
    yaxis = list(title = "Cazuri noi confirmate"),
    xaxis = list(title = "Data"),
    hovermode = "compare",
    margin = list(
      b = 10,
      t = 10,
      pad = 2
    )
  )
```
 
### Distributia cazurilor dupa tipul lor

```{r}
df_EU <- coronavirus %>%
  dplyr::group_by(country, type) %>%
  dplyr::summarise(total = sum(cases)) %>%
  tidyr::pivot_wider(
    names_from = type,
    values_from = total
  ) %>%
  dplyr::mutate(unrecovered = confirmed - ifelse(is.na(recovered), 0, recovered) - ifelse(is.na(death), 0, death)) %>%
  dplyr::arrange(confirmed) %>%
  dplyr::ungroup() %>%
  dplyr::mutate(country = trimws(country)) %>%
  dplyr::mutate(country = factor(country, levels = country))

plotly::plot_ly(
  data = df_EU,
  x = ~country,
  y = ~ confirmed,
  type = "bar",
  name = "Confirmati",
  marker = list(color = active_color)
) %>%
  plotly::add_trace(
    y = ~death,
    name = "Decedati",
    marker = list(color = death_color)
  ) %>%
  plotly::layout(
    barmode = "stack",
    yaxis = list(title = "Total Cazuri"),
    xaxis = list(title = ""),
    hovermode = "compare",
    margin = list(
      b = 10,
      t = 10,
      pad = 2
    )
  )
```


### Date

    
```{r}
bar_chart <- function(label, width = "100%", height = "14px", fill = "#00bfc4", background = NULL) {
            bar <- htmltools::div(style = list(background = fill, width = width, height = height))
            chart <- htmltools::div(style = list(flexGrow = 1, marginLeft = "6px", background = background), bar)
  htmltools::div(style = list(display = "flex", alignItems = "center"), label, chart)
}


tbl <- reactable::reactable(dft,
                            pagination = FALSE,
                            highlight = TRUE,
                            height = 400,
                            sortable = TRUE,
                            borderless = TRUE,
                            defaultPageSize = nrow(dft),
                            defaultSortOrder = "desc",
                            defaultSorted = "date",
                            columns = list(
date = reactable::colDef(name = "Data", minWidth = 50, maxWidth = 100),
confirmed = reactable::colDef(name = "Confirmati",  minWidth = 50, maxWidth = 100),
recovered = reactable::colDef(name = "Vindecati",  minWidth = 50, maxWidth = 100),
death = reactable::colDef(name = "Decese",  minWidth = 50, maxWidth = 100),
daily_confirmed_5D = reactable::colDef(name = "Confirmati la @5zile",  minWidth = 50, maxWidth = 100),
daily_confirmed_7D = reactable::colDef(name = "Confirmati la @7zile",  minWidth = 50, maxWidth = 100),
daily_confirmed_14D = reactable::colDef(name = "Confirmati la @14zile",  minWidth = 50, maxWidth = 100),
recover_rate = reactable::colDef(name = "Rata Vindecati",  minWidth = 50, maxWidth = 200, defaultSortOrder = "desc",
cell = function(value) {
                     # Format as percentages with 1 decimal place
                     value <- paste0(format(round(value * 100, 2), nsmall = 1), "%")
                     bar_chart(value, width = value, fill = "green", background ="#e1e1e1") },  align = "left"),
death_rate = reactable::colDef(name = "Rata decese",  minWidth = 50, maxWidth = 200,
                      defaultSortOrder = "desc",cell = function(value) {
                     # Format as percentages with 1 decimal place
                     value <- paste0(format(round(value * 100, 2), nsmall = 1), "%")
                     bar_chart(value, width = value, fill = "red", background = "#e1e1e1") }, align = "left"))
)

htmltools::div(class = "standings",
    paste("Click pe numele coloanei pentru a rearanja datele in tabel. Ultimul update al datelor a fost: ", max(dft$date)),
  tbl
)


```


### Despre

Acest dashboard este o replica inspirata de [articolul](https://www.statsandr.com/blog/how-to-create-a-simple-coronavirus-dashboard-specific-to-your-country-in-r/){target="_blank"} lui [Antoine Soetewey](https://www.antoinesoetewey.com).


Ulterior, dashboardurile dezvoltate de [Rami Krispin](https://ramikrispin.github.io/coronavirus_dashboard/){target="_blank"}, cat si pachetele de date COVID-19 au reprezentat un punct de explorare al pachetului R ['{flexdashboard}'](http://rmarkdown.rstudio.com/flexdashboard).

**Code** Codul este scris folosind R.

**Data** Momentan folosesc datele disponibile in pachetul de dezvoltare, dar initial s-au folosit date de intrare din pachetul R [`{coronavirus}`](https://github.com/RamiKrispin/coronavirus){target="_blank"}. 

```
install.packages("devtools")
devtools::install_github("RamiKrispin/coronavirus")
```

Datele brute au sursa datele de la Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE) Coronavirus.
Acestea sunt actualizate zilnic, dar acest dashboard se actualizeaza la cateva zile, manual.


**Ultimul update** Dashboardul a fost actualizat ultima oara in data de `r format(Sys.time(), "%b %d, %Y")`. Datele raportate sunt pana la data de `r format(max(coronavirus$date), "%b %d, %Y")`

Pentru alte proiecte de R, ma gasesti pe [pagina mea personala](https://ineszz.rbind.io/blog/?utm_source=referral&utm_medium=link&utm_campaign=covid-19-ro-dash/).